package org.tis.tools.model.enums;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * 路径参数请求类型
 * Created by chenchao
 * Created on 2018/9/30 14:42
 */
public enum IRequestMethod implements BaseEnum {

    /** 请求类型:GET请求 */
    GET("GET","GET请求"),

    /** 请求类型:HEAD请求 */
    HEAD("HEAD","HEAD请求"),

    /** 请求类型:POST请求 */
    POST("POST","POST请求"),

    /** 请求类型:PUT请求 */
    PUT("PUT","PUT请求"),

    /** 请求类型:PATCH请求 */
    PATCH("PATCH","PATCH请求"),

    /** 请求类型:DELETE请求 */
    DELETE("DELETE","DELETE请求"),

    /** 请求类型:OPTIONS请求 */
    OPTIONS("OPTIONS","OPTIONS请求"),

    /** 请求类型:TRACE请求 */
    TRACE("TRACE","TRACE请求");

    private final String value;

    private final String name;

    IRequestMethod(final String value,final String name){
        this.name = name;
        this.value = value;
    }

    @Override
    public String getValue() { return this.value; }

    @Override
    public Serializable deserialze() { return value; }

    public  String getDesc(){ return this.name; }

    @Override
    public String toString() { return name; }

    public static IRequestMethod matchRequestMethod(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }

        for (IRequestMethod type : IRequestMethod.values()) {
            if (type.getValue().equals(value) || type.toString().equals(value)) {
                return type;
            }
        }
        return null;
    }
}
